package example;

import java.lang.reflect.Method;
import java.util.HashMap;
import squares.*;
import borders.*;
import squares.Square.TemperatureType;
import dungeons.*;
import dungeons.Shaft.shaftDirection;

public class ProjectExample {
	
	public Square shaftSquare1,shaftSquare2,shaftSquare3,shaftSquare4,shaftSquare5,shaftSquare6,shaftSquare7,shaftSquare8;
	public Square plateauSquare1,plateauSquare2,plateauSquare3,plateauSquare4,plateauSquare5,plateauSquare6,plateauSquare7;
	public Shaft<Square> shaft;
	public Plateau<Square> plateau;
	public CompositeDungeon<Square> compositeDungeon;
	public TransparentSquare transparentSquare1;
	public RockSquare rock;
	
	
	public ProjectExample() throws InvalidTemperatureException, InvalidHumidityException, IllegalTemperatureTypeException, IllegalArgumentException, IllegalSquareException, SecurityException, NoSuchMethodException
	{
		this.shaft = new Shaft<Square>(100,shaftDirection.X);
		 shaftSquare1 = new Square(400, TemperatureType.CELSIUS, 20, true, false,null, new Open(shaftSquare1), new Open(shaftSquare1), new Open(shaftSquare1), null, null);
		 
		 shaftSquare2 = new Square(400, TemperatureType.CELSIUS, 40, false, false,new Open(shaftSquare2), new Open(shaftSquare2), new Open(shaftSquare2), new Open(shaftSquare2), null, null);
		 shaftSquare3 = new Square(1000, TemperatureType.CELSIUS, 20, false, false,new Open(shaftSquare3), new Open(shaftSquare3), new Open(shaftSquare3), new Open(shaftSquare3), null, null);
		 shaftSquare4 = new Square(400, TemperatureType.CELSIUS, 20, false, true,new Open(shaftSquare4), new Open(shaftSquare4), new Open(shaftSquare4), new Open(shaftSquare4), new Door(shaftSquare4,true), null);
		 shaftSquare5 = new Square(600, TemperatureType.CELSIUS, 35, false, false,new Open(shaftSquare5), new Open(shaftSquare5), new Open(shaftSquare5), new Open(shaftSquare5), null, null);
		 shaftSquare6 = new Square(-200, TemperatureType.CELSIUS, 20, false, true,new Open(shaftSquare6), new Open(shaftSquare6), new Open(shaftSquare6), new Open(shaftSquare6), null, null);
		 shaftSquare7 = new Square(300, TemperatureType.CELSIUS, 0, false, false,null, new Open(shaftSquare7), new Open(shaftSquare7), new Open(shaftSquare7), null, null);
		 shaftSquare8 = new Square(400, TemperatureType.CELSIUS, 20, false, false,null, new Open(shaftSquare8), new Open(shaftSquare8), new Open(shaftSquare8), null, null);
		 transparentSquare1 = new TransparentSquare(400,TemperatureType.CELSIUS,40,false,false,Direction.NORTH,false);
		 shaft.addSquare(shaftSquare3, 3, 0, 0);
		 shaft.addSquare(shaftSquare4, 4,0,0);
		 shaft.addSquare(shaftSquare5, 5, 0, 0);
		 shaft.addSquare(shaftSquare6,6, 0, 0);
		 shaft.addSquare(shaftSquare7, 7, 0, 0);
		 shaft.addSquare(shaftSquare8, 8, 0, 0);
		 shaft.addSquare(shaftSquare1, 1, 0, 0);
		 shaft.addSquare(shaftSquare2, 2, 0, 0);
		 plateau = new Plateau<Square>(100,100);
		 plateauSquare1 = new Square(45,TemperatureType.CELSIUS,75,false,false,null,new Open(plateauSquare1),new Door(plateauSquare1,true),null,null,null);
		 plateauSquare2 = new Square(200, TemperatureType.CELSIUS, 20, false, false,new Door(plateauSquare2,true), new Open(plateauSquare2), new Open(plateauSquare2), new Open(plateauSquare2), null, null);
		 plateauSquare3 = new Square(5, TemperatureType.CELSIUS, 40, false, false,new Door(plateauSquare3,true), new Open(plateauSquare3), new Open(plateauSquare3), new Open(plateauSquare3), null, null);
		 plateauSquare4 = new Square(240, TemperatureType.CELSIUS, 20, false, true,new Open(plateauSquare4), new Open(plateauSquare4), new Open(plateauSquare4), new Door(plateauSquare4,true), new Door(plateauSquare4,true), null);
		 plateauSquare5 = new Square(24, TemperatureType.CELSIUS, 35, false, false,null, new Open(plateauSquare5), new Open(plateauSquare5), new Open(plateauSquare5), null, null);
		 plateauSquare6 = new Square(-23, TemperatureType.CELSIUS, 75, false, true,new Open(plateauSquare6), new Open(plateauSquare6), new Open(plateauSquare6), new Open(plateauSquare6), null, null);
		 plateauSquare7 = new Square(4534, TemperatureType.CELSIUS, 0, false, false,new Open(plateauSquare7), new Open(plateauSquare7), new Open(plateauSquare7), new Open(plateauSquare7), null, null);
		 rock = new RockSquare();
		 plateau.addSquare(plateauSquare1, 1, 0, 0);
		 plateau.addSquare(plateauSquare2, 2, 1, 0);
		 plateau.addSquare(plateauSquare3, 2, 2, 0);
		 plateau.addSquare(plateauSquare4, 2, 3, 0);
		 plateau.addSquare(plateauSquare5, 3, 0, 0);
		 plateau.addSquare(plateauSquare6, 34, 0, 0);
		 plateau.addSquare(plateauSquare7, 4, 0, 0);
		 plateau.addSquare(transparentSquare1, 4, 1, 0);
 
		 plateau.addSquare(rock, 5, 0, 0);
		 System.out.println(rock.getTemperature());
		 rock.adjustTemperature();
		 System.out.println(rock.getTemperature());
		 compositeDungeon = new CompositeDungeon<Square>(500,500,500);
		 plateauSquare6.addTeleportableSquare(plateauSquare7);
		 HashMap<Method,Object> conditions = new HashMap<Method,Object>();
		 double z = 200;
		 conditions.put(Square.class.getMethod("TemperatureHigherOrEqualTo",double.class),z);
		 conditions.put(Square.class.getMethod("isRockSquare"), null);
		 System.out.println(plateau.getAllSquaresWhere(conditions));
		 
		 
		 
		 
		 
	}
	public static void main(String[] args) throws IllegalArgumentException, InvalidTemperatureException, InvalidHumidityException, IllegalTemperatureTypeException, IllegalSquareException, SecurityException, NoSuchMethodException
	{
		ProjectExample ex = new ProjectExample();
		System.out.println(" the dungeons have been build.");
		System.out.println("on this moment, you can not get from squares in the plateau to the squares in the shaft");
		System.out.println("shaft<-plateau : possible = "+ Dungeon.canGetTo(ex.plateauSquare2, ex.shaftSquare1));
		System.out.println("shaft->plateau : possible = " + Dungeon.canGetTo(ex.shaftSquare1, ex.plateauSquare2));
		System.out.println("now we do make it possible to teleport to the plateau by one square");
		ex.shaftSquare4.setTeleportationPossible(true);
		ex.shaftSquare4.addTeleportableSquare(ex.plateauSquare3);
		System.out.println("now we show you can get to the plateau from the shaft, but not the other way");
		System.out.println("shaft<-plateau : possible = "+ Dungeon.canGetTo(ex.plateauSquare2, ex.shaftSquare1));
		System.out.println("shaft->plateau : possible = " + Dungeon.canGetTo(ex.shaftSquare1, ex.plateauSquare2));
		System.out.println("shaft->plateau via second space : possible = " + Dungeon.canGetTo(ex.shaftSquare3, ex.plateauSquare7));
		System.out.println("now we check if squares are in same space");
		System.out.println(Dungeon.isConnected(ex.shaftSquare1, ex.plateauSquare5));
		System.out.println("now we put the dungeon adjacent in a composite dungeon");
		ex.compositeDungeon.addDungeon(ex.shaft, 2, 1, 1);
		ex.compositeDungeon.addDungeon(ex.plateau, 2, 2, 1);
		System.out.println("and check again");
		System.out.println(Dungeon.isConnected(ex.shaftSquare1, ex.plateauSquare5));
		
		
		System.out.println("now we check if there are rockSquares of 200 degrees in the plateau");
		HashMap<Method,Object> conditions = new HashMap<Method,Object>();
		 double z = 200;
		 conditions.put(Square.class.getMethod("TemperatureHigherOrEqualTo",double.class),z);
		 conditions.put(Square.class.getMethod("isRockSquare"), null);
		 System.out.println(ex.plateau.getAllSquaresWhere(conditions));
		
	}
}
